package com.greet.controller.user;

import com.greet.entity.Setmeal;
import com.greet.result.Result;
import com.greet.service.SetmealService;
import com.greet.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/setmeal")
public class SetmealViewController {
    @Autowired
    private SetmealService setmealService;

    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    //eg. key: setmealCache::100
    @GetMapping("/list")
    public Result<List<Setmeal>> getByCategoryId(Long categoryId){
        List<Setmeal> setmealList = setmealService.getViewBycategoryId(categoryId);
        return Result.success(setmealList);
    }

    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishItemVOS(@PathVariable Long id){
        List<DishItemVO> dishItemVOList = setmealService.getDishItemVOSById(id);
        return Result.success(dishItemVOList);
    }
}
